package leetcode.editor.cn.q1_300.q150;

/**
 * 规律：只要是想要 nlogn 优先想到二分法
 *
 * @author qidi
 * @date 2022-01-21 15:29:24
 */
class Q0162_FindPeakElement {

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int findPeakElement(int[] nums) {
            int length = nums.length;
            int left = 0;
            int right = length - 1;
            while (left < right) {
                int mid = left + right >> 1;
                if (nums[mid] > nums[mid + 1]) {
                    //情况1
                    right = mid;
                } else {
                    //情况2
                    left = mid + 1;
                }
            }
            return right;
        }
    }
    //leetcode submit region end(Prohibit modification and deletion)


    public static void main(String[] args) {
        Solution solution = new Q0162_FindPeakElement().new Solution();
        System.out.println(solution.findPeakElement(new int[]{3, 1, 2}));
        System.out.println(solution.findPeakElement(new int[]{2, 1, 3}));
        System.out.println(solution.findPeakElement(new int[]{3}));
        System.out.println(solution.findPeakElement(new int[]{2, 3}));
        System.out.println(solution.findPeakElement(new int[]{3, 2, 1, 0}));
        System.out.println(solution.findPeakElement(new int[]{0, 1, 2, 3}));
        System.out.println(solution.findPeakElement(new int[]{1, 2, 3, 1}));
        System.out.println(solution.findPeakElement(new int[]{1, 2, 1, 3, 5, 6, 4}));
    }
}